#include "game.h"

void menu()
{
    printf("**************************\n");
    printf("**********1.game**********\n");
    printf("**********0.exit**********\n");
    printf("**************************\n");
}

void game()
{

    char board[ROW][COL];
    char ret = 0;
    init_board(board,ROW,COL);//init board to ' '
    print_board(board,ROW,COL);

    while(1)
    {
        player_move(board,ROW,COL);
        print_board(board,ROW,COL);
        ret = is_win(board,ROW,COL);
        if (ret != 'C')
        {
            break;
        }

        computer_move(board,ROW,COL);
        print_board(board,ROW,COL);
        ret = is_win(board,ROW,COL);
        if (ret != 'C')
        {
            break;
        }
    }

    //判断输赢
    //电脑赢:#，因为电脑执#，判断函数返回值用所执棋子类型
    //玩家赢:*，同理
    //平局：Q，棋盘占满，但没有返回任何一种类型的棋子
    //游戏继续：C

    if (ret == '#')
        printf("computer win\n");
    else if (ret == '*')
        printf("player win\n");
    else if (ret == 'Q')
        printf("draw\n");
}

int main()
{
    int input = 0;
    srand((unsigned int)time(NULL));
    do
    {
        menu();
        printf("please choose:");
        scanf("%d",&input);
        switch(input)
        {
            case 1:
                game();
                break;
            case 0:
                printf("exit game\n");
                break;
            default:
                printf("input error,plase input again");
                break;
        }
    }while(input);
    return 0;
}
